package com.cz.nongyetongv5.adapter.config;

import android.app.ActivityManager;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import java.util.List;

public class CommonConstants {

	/**
	 * 农业通调试标签
	 */
	public static final String LOG_TAG = "NONGYETONG_DEBUG";

	/**
	 * 存数数据的SharedPreferences 的名字
	 */
	public static final String SHARED_REFERENCES_TAG = "nongyetong";

	/**
	 * 重新初始化数据的变量保存，判断是否初始化了
	 */
	public static final String SHARED_REFERENCES_REINITDATA = "nytreinit";



	/**
	 * 三秒后进入主界面
	 */
	public static final long INTOTIME = 1000 * 3;

	/**
	 * 数据名称
	 */
	public static final String DBNAME = "nongyetong2.db3";

	/**
	 * 网址的前缀
	 */
	// public static final String URLSUFFER = "http://jg.czfood360.cn/";

	// public static final String URLSUFFER = "http://192.168.0.123:8001/";

	/**
	 * 数据库的版本
	 */
	public static final int DATABASE_VERSION = 7;

	/**
	 * 密码
	 */
	public static final String CHAT_USER_PASSWORD = "cznongpassword";

	/**
	 * 检测服务是否运行
	 *
	 * @param mContext
	 * @param className
	 * @return
	 */
	public static boolean isServiceRun(Context mContext, String className) {
		boolean isRun = false;

		ActivityManager activityManager = (ActivityManager) mContext
				.getSystemService(Context.ACTIVITY_SERVICE);

		List<ActivityManager.RunningServiceInfo> serviceList = activityManager
				.getRunningServices(40);

		int size = serviceList.size();

		for (int i = 0; i < size; i++) {
			if (serviceList.get(i).service.getClassName().equals(className) == true) {
				isRun = true;
				break;
			}
		}

		return isRun;
	}

	/**
	 * 检测是否存在网络
	 *
	 * @param context
	 * @return
	 */
	public static boolean isNetworkConnected(Context context) {
		if (context != null) {
			ConnectivityManager mConnectivityManager = (ConnectivityManager) context
					.getSystemService(Context.CONNECTIVITY_SERVICE);
			NetworkInfo mNetworkInfo = mConnectivityManager
					.getActiveNetworkInfo();

			if (mNetworkInfo != null) {
				return mNetworkInfo.isAvailable();
			}
		}
		return false;
	}

	/**
	 * 检测服务器返回的数据是否oK
	 *
	 * @return
	 */
	public static boolean serverIsOk(String status) {

		if ("true".equals(status) || "1".equals(status)) {

			return true;
		} else {
			return false;
		}

	}

}
